<?php

namespace App\Services;

use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;
class SteamDtClientService
{
    public function headers(): array
    {
        return [
            'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
            'Content-Type' => 'application/json; charset=utf-8',
            'Accept' => 'application/json',
            'x-app-version' => '1.0.0',
            'x-device-id' => '8dbb22ef-2962-43b8-a347-d26a7a268aa2',
            'x-device' => 1,
            'x-currency' => 'CNY',
            'origin' => 'https://steamdt.com',
            'referer' => 'https://steamdt.com/',
        ];
    }

    public function cookies(): array
    {
        return [
            'HMACCOUNT' => 'D018874CCE836561',
            'Hm_lpvt_70b50b426bea36bf4042c7522b5465e3' => '1727052668',
            'Hm_lvt_70b50b426bea36bf4042c7522b5465e3' => '1726623699,1726906412,1726964373,1727051456',
            'SDT_DeviceId' => '8dbb22ef-2962-43b8-a347-d26a7a268aa2',
            'SDT_HideAgreement' => '1',
            'SDT_KnifeRatioSort' => 'purchaseBest',
            'SDT_PlatformList' => '%5B%22steam%22%2C%22c5%22%2C%22youpin%22%2C%22buff%22%5D',
            'SDT_RateList' => '%5B%7B%22name%22%3A%22%E4%BA%BA%E6%B0%91%E5%B8%81%22%2C%22icon%22%3A%22%C2%A5%22%2C%22currency%22%3A%22CNY%22%2C%22rate%22%3A1%7D%2C%7B%22name%22%3A%22%E7%BE%8E%E5%85%83%22%2C%22icon%22%3A%22%24%22%2C%22currency%22%3A%22USD%22%2C%22rate%22%3A0.1418%7D%2C%7B%22name%22%3A%22%E5%8D%A2%E5%B8%83%22%2C%22icon%22%3A%22%E2%82%BD%22%2C%22currency%22%3A%22RUB%22%2C%22rate%22%3A13.1136%7D%2C%7B%22name%22%3A%22%E6%AC%A7%E5%85%83%22%2C%22icon%22%3A%22%E2%82%AC%22%2C%22currency%22%3A%22EUR%22%2C%22rate%22%3A0.127%7D%5D',
            '_ga' => 'GA1.1.2131400555.1726623699',
            '_ga_TEZ3M92XBC' => 'GS1.1.1727051456.8.1.1727052675.0.0.0',
            '_gcl_au' => '1.1.417651244.1726623699',
        ];
    }

    /**
     * @throws ConnectionException
     */
    public function get($url)
    {
        return Http::withHeaders($this->headers())->withCookies($this->cookies(),'steamdt.com')
            ->get($url)
            ->json();
    }

    /**
     * @throws ConnectionException
     */
    public function post($url, $params)
    {
        return Http::withHeaders($this->headers())->withCookies($this->cookies(),'steamdt.com')
            ->post($url, $params)
            ->json();
    }

}
